import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'
import special from './modules/special'
import map from './modules/map'

Vue.use(Router)

export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: '/',
    meta: { title: '概况', icon: '&#xe67b;', level: 1 },
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        meta: { title: '概况', icon: '&#xe67b;', level: 1 },
        component: () => import('@/views/home/index.vue')
      }
    ]
  },
  map,
  special,
  {
    path: '/system',
    component: Layout,
    redirect: '/system/mine',
    name: 'system',
    meta: { title: '我的', icon: '&#xe6c2;', level: 3 },
    children: [
      {
        path: 'mine',
        name: 'mine',
        component: () => import('@/views/system/index'), //
        meta: { title: '我的', icon: '&#xe60c;', level: 3 }
      },
      {
        path: 'aboutApp',
        name: 'aboutApp',
        component: () => import('@/views/system/aboutApp'), //
        meta: { title: '关于软件', icon: '&#xe60c;', level: 4 },
        hidden: true
      },
      {
        path: 'changePassword',
        name: 'changePassword',
        component: () => import('@/views/system/changePassword'), //
        meta: { title: '修改密码', icon: '&#xe60c;', level: 4 },
        hidden: true
      },
      {
        path: 'feedback',
        name: 'feedback',
        component: () => import('@/views/system/feedback'), //
        meta: { title: '意见反馈', icon: '&#xe60c;', level: 4 },
        hidden: true
      },
      {
        path: 'personalInfo',
        name: 'personalInfo',
        component: () => import('@/views/system/personalInfo'), //
        meta: { title: '个人信息', icon: '&#xe60c;', level: 4 },
        hidden: true
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/OAuthSingleLogin',
    component: () => import('@/views/login/OAuthSingleLogin'),
    hidden: true,
    label: 'hidden'
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}
router.afterEach((to, form) => {
  const app = document.getElementById('app')
  if (to.query.current === '消防管理') {
    if (!Array.from(app.classList).includes('no-icon')) {
      app.className = 'app no-icon'
    }
  } else {
    app.className = 'app'
  }
})

export default router
